import pygame
from pygame.sprite import Sprite

class Alien(Sprite):
    def __init__(self, ai_game):
        super().__init__()
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        
        #加载外星人图像
        self.image = pygame.image.load('images/wjj.bmp')
        #缩放外星人图像
        original_width, original_height = self.image.get_size()
        self.image = pygame.transform.scale(self.image, (original_width / 3, original_height / 3))
        #设置其rect属性
        self.rect = self.image.get_rect()

        
        #先将每个新外星人放在屏幕左上角附近
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height
        
        #存储外星人的精确水平位置
        self.x = float(self.rect.x)
        
        
    #判断是否撞到屏幕边缘
    def check_edges(self):
        screen_rect = self.screen.get_rect()
        return (self.rect.right >= screen_rect.right) or (self.rect.left <= 0)

        
    #移动外星人
    def update(self):
        #左右移动
        self.x += (self.settings.alien_speed * self.settings.fleet_direction)
        self.rect.x = self.x
    